home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 18052 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.3 KB  |  40 lines

  1. Path: news1.intercall.com!usenet
  2. From: engevar@intercall.com (Steven Ovits)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: main()
  5. Date: Thu, 18 Apr 1996 20:58:34 GMT
  6. Organization: Intercall Inc.
  7. Message-ID: <4l614s$336@news1.intercall.com>
  8. References: <3174c0dc.7652220@news.flex.com.au> <829766541snz@j-bg.demon.co.uk> <Dq1C8B.3sC@news.hawaii.edu>
  9. NNTP-Posting-Host: ts3-144.intercall.com
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. Alvin Nonaka <xea0005@co.honolulu.hi.us> wrote:
  13.  
  14. >>In article <3174c0dc.7652220@news.flex.com.au>
  15. >>> I have come across two different ways that 2 different beginners books
  16. >>> recommend that every program should start.  Could someone please tell
  17. >>> me which one is the "BEST" or proper way?
  18.  
  19. [snip]
  20.  
  21. >'main' can't return. Calling 'exit' is better because the call to exit 
  22. >'cleans up' all resource allocations (which you are supposed to handle) 
  23. >left pending in your code.
  24.  
  25. >The value passed to exit is 'returned' and control passes to the host 
  26. >environment.
  27.  
  28. Since this is in a C++ group, I'll dispense with C's main().
  29. From "The C++ Programming Language," 2 ed, Stroustrup, p.485.
  30.  
  31. The function main() may be defined as
  32.   int main() { /* ... */ }
  33. or
  34.   int main(int argc, char* argv[]) { /* ... */ }
  35.  
  36. A return statement in main() has the effect of calling exit()
  37. with the return value as the argument.
  38.  
  39.  
  40.